<template>
	<view class="container">
		<h1>国际能源通-采购商登录</h1>
		<view class="logo">
			<!-- 这里放置你的Logo -->
			<image src="/static/logo.png" class="logo-img"></image>
		</view>
		<view class="form">
			<input v-model="tele" type="text" placeholder="用户名" class="input"></input>
			<input v-model="password" type="password" placeholder="密码" class="input"></input>
			<view class="button" @click="login">登录</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				buyer: {
					tele: null,
					password: null,
					mpanyName: null,
					unifiedCreditCode: null,
					qualificationCertificateIma: null,
					avatarImage: null,
					buyerAccountrStatus: null,
					balance: null,
					address: null,
					token: null,
				},
				tele: '',
				password: ''
			}
		},
		created() {
			console.log(this.$u.config.v);
		},
		methods: {
			login() {
				uni.request({
					url: 'http://localhost:8088/buyer-account/login',
					method: 'POST',
					data: {
						tele: this.tele,
						password: this.password
					},
					header: {
						'content-type': 'application/json'
					},
					success: (res) => {
						console.log(res.data);
						if(res.data.code == 1) {
							const token = res.data.data.token; // 获取响应中的token
							// 登录成功后将 token 存储在 localStorage 中
							localStorage.setItem('token', token);
							console.log('请求成功：', res.data.data);
							uni.switchTab({
								url: '/pages/index/index'
							});
						} else {
							uni.showToast({
							  title: res.data.msg,
							  icon: 'none', // 提示图标，可选值：'success'、'loading'
							  duration: 1500 // 持续时间，单位为毫秒，默认为1500
							});
						}
						
					},
					fail: (err) => {
						console.error('请求失败：', err);

					}
				});
			}
		}

	}
</script>

<style lang="scss">
	@import "uview-ui/index.scss";

	.container {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		height: 100vh;
	}

	.logo {
		margin-bottom: 20px;
	}

	.logo-img {
		width: 100px;
		height: 100px;
	}

	.form {
		width: 80%;
	}

	.input {
		width: 100%;
		padding: 10px;
		margin-bottom: 20px;
		border: 1px solid #ccc;
		border-radius: 5px;
	}

	.button {
		width: 100%;
		padding: 10px;
		text-align: center;
		background-color: #007bff;
		color: #fff;
		border-radius: 5px;
		cursor: pointer;
	}

	.button:hover {
		background-color: #0056b3;
	}
</style>